<!DOCTYPE html>
<html>
<head>
  <title></title>
  <script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
  <script type="text/javascript" src="../lib/notice.js"></script>
  <script type="text/javascript">

    function log(s){
      $('#message').append(s).append('\n');
    }

    $(function(){
      $('#send').on('click', function(){
        $.post('http://127.0.0.1:7890/push', {
          id: '123',
          project: 'alipay',
          message: 'send message to client id=123'
        }, function(data){
          log('send push : ' + data);
        });
      });

      var url = 'ws://127.0.0.1:7890/notice?id=123&sign=d19c82b1052d62b39129b0df42b7f27c&project=alipay';

      //监听窗口关闭事件，当窗口关闭时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。
      var notice = new Notice(url);
      notice.onmessage = function(message){
        log('recv message: ' + message);
      };
    });
  </script>

</head>
<body>
  <input type="button" name="send" id="send" value="send" />
  <textarea id="message" rows="20" cols="600"></textarea>
</body>
</html>